#include "q_shared.h"
#include "bg_global.h"
#include "bg_gamex86funcs.h"
#include <stdio.h>
#define WIN32_LEAN_AND_MEAN
#include <windows.h>

extern int (__cdecl *syscall)( int arg, ... );

__declspec(dllexport) void __cdecl trap_Error(char *error)
{
	syscall(SYSCALL_ERROR, error);
}

__declspec(dllexport) qhandle_t __fastcall trap_R_RegisterShader(char *path)
{
	return (qhandle_t)syscall(SYSCALL_REGISTERSHADER, path);
}

__declspec(dllexport) qhandle_t __fastcall trap_R_RegisterShaderNoMip(char *path)
{
	return (qhandle_t)syscall(SYSCALL_REGISTERSHADERNOMIP, path);
}

__declspec(dllexport) sfxHandle_t __fastcall trap_S_RegisterSound(char *path)
{
	return (sfxHandle_t)syscall(SYSCALL_REGISTERSOUND, path);
}

__declspec(dllexport) void __cdecl trap_S_StartSound(vec3_t origin, int entityNum, int channel, sfxHandle_t handle)
{
	syscall(SYSCALL_STARTSOUND, origin, entityNum, channel, handle);
}

__declspec(dllexport) void __cdecl trap_Printf(char *fmt, ...)
{
	va_list args;
	char buf[1024];
	va_start(args, fmt);
	vsprintf(buf, fmt, args);
	va_end(args);
	//gi->Printf(fmt, buf); //fuck this noise. use a syscall instead
	syscall(SYSCALL_PRINT, buf);
}

__declspec(dllexport) void __cdecl trapped_Cvar_VariableBuffer( const char *var_name, char *buffer, int bufsize )
{
	gi->Cvar_VariableStringBuffer(var_name, buffer, bufsize);
}

__declspec(dllexport) int __cdecl trapped_FS_FOpenFile( char *fileName, fileHandle_t *f, fsMode_t mode )
{
	return gi->FS_FOpenFile( fileName, f, mode );
}

__declspec(dllexport) int __cdecl trapped_FS_Read( void *buffer, int len, fileHandle_t f )
{
	return gi->FS_Read(buffer, len, f);
}

__declspec(dllexport) void __cdecl trapped_FS_FCloseFile( fileHandle_t f )
{
	gi->FS_FCloseFile(f);
}